<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>课程列表中表格的修改功能</title>
    <script src="/jquery/jquery-3.2.1.min.js"></script>
    <script src="/layui/layui.js"></script>
    <link rel="stylesheet" href="/layui/css/layui.css">
    <style>
        body{
            background-color:rgb(243,243,243);
        }
        .box{
            width:700px;
            height: 440px;
            margin: 0 auto;
        }
        .lab{
            width: 100px;
            margin-left: -20px;
        }
        .layui-form-item{
            margin-top: 20px;
        }
    </style>
</head>
<body>
<div>
    <form class="layui-form" lay-filter="layForm">
    <div class="box layui-form">
        <div class="layui-form-item">
            <label class="layui-form-label">课程编号：</label>
            <div class="layui-input-inline">
                <input type="text" name="id" id="cId" lay-verify="title" autocomplete="off" placeholder="" class="layui-input" disabled>
            </div>
            <label class="layui-form-label" style="margin-left: 70px;">课程名称：</label>
            <div class="layui-input-inline">
                <input type="text" id="courseName" name="courseName" lay-verify="title" autocomplete="off" placeholder="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <div>
                <label class="layui-form-label">商品价格：</label>
                <div class="layui-input-inline">
                    <input type="text" id="courseNprice" name="courseNprice" lay-verify="title" autocomplete="off" placeholder="" class="layui-input">
                    <input type="hidden" id="coursePrice" name="coursePrice" lay-verify="title" autocomplete="off" placeholder="" class="layui-input">
                </div>
            </div>

            <div class="layui-inline">
                <label class="layui-form-label" style="margin-left: 70px;">商品状态：</label>
                <div class="layui-input-inline">
                    <select name="courseStatus" lay-verify="required" style="width: 190px; height: 38px;" lay-filter="text" id="courseStatus">
                        <option value="2">上架</option>
                        <option value="3">下架</option>
                    </select>
                </div>
            </div>
        </div>

        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label lab">课程关键字：</label>
            <div class="layui-input-block">
                <textarea placeholder="请输入内容" class="layui-textarea" name="coursePrimary" id="coursePrimary" style="resize: none;"></textarea>
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">课程介绍：</label>
            <div class="layui-input-block">
                <textarea placeholder="请输入内容" class="layui-textarea" id="courseInfo" style="resize: none;"></textarea>
            </div>
        </div>
    </div>
    <input id="updateDate" hidden/>
    <input id="courseId" hidden/>
</form>
</div>
</body>
<script>
    layui.use(['jquery','layer','table','form'],function() {
        var $ = layui.jquery;
        var layer = layui.layer;
        var table = layui.table;
        var form = layui.form;
        var courseData = JSON.parse(localStorage.getItem("courseData"));
        $("#cId").val(courseData.id);
        $("#courseName").val(courseData.courseName);
        $("#courseNprice").val(courseData.courseNprice);
        $("#coursePrice").val(courseData.courseNprice);
        $("#coursePrimary").val(courseData.coursePrimary);
        $("#courseInfo").val(courseData.courseInfo);
        $("#courseStatus").val(courseData.courseStatus);
        form.on('select(text)', function(data){
            if(data.value==2){
                $("#courseStatus").val(2);
            }else if(data.value==3){
                $("#courseStatus").val(3);
            }
        });
        $("#courseId").val(courseData.courseId);
        //获取form页面的所有内容
        var layForm = form.val("layForm");
        form.render();//重新渲染
    })
</script>
</html>